﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Xiezl.Common.Data;
using Xiezl.Common.EFExpressions;
using System.Linq.Expressions;

namespace Xiezl.Common.Web.PgExp
{
    /// <summary>
    /// 页面查询产品条件
    /// </summary>
    public class PgQueryProductExp : IEFQueryExpression<Product>
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string Specification { get; set; }
        public Guid CategoryId { get; set; }     


        public Expression<Func<Product, bool>> GetExpression()
        {

            var exp = EFExpression<Product>.CreateSignleLogic(ELogicType.And)
                .Like(o => o.Code, Code)
                .Like(o => o.Name, Name)
                .Like(o => o.Specification, Specification);

            //以上写法或者写成如下格式
            var exp2= EFExpression<Product>.Create()
                .AndLike(o => o.Code, Code)
                .AndLike(o => o.Name, Name)
                .AndLike(o => o.Specification, Specification);


            if (CategoryId != Guid.Empty)
                exp = exp.Equal(o => o.CategoryId, CategoryId);           

            return exp.GetExpression();
        }
    }
}